fix(ignore): preserve escaped trailing spaces in gitignore patterns - #3492
Open
baima365-web wants to merge 1 commit into
Open
fix(ignore): preserve escaped trailing spaces in gitignore patterns#3492baima365-web wants to merge 1 commit into
baima365-web wants to merge 1 commit into
Conversation
Contributor
|
I didn't read the surrounding code, but you should probably check if the number of preceding backslashes is odd. |
…trailing spaces Update the trailing space trimming logic to properly handle multiple preceding backslashes per ltrzesniewski's suggestion: - Count the number of consecutive backslashes before each trailing space - If odd count: space is escaped, preserve it and stop trimming - If even count (including zero): space is unescaped, trim it This fixes cases like '\\ ' (two backslashes + space) which should be trimmed to '\\' (escaped backslash), while '\\ ' (three backslashes + space) should be preserved as '\\ ' (escaped backslash + escaped space). Fixes BurntSushi#3485
baima365-web
force-pushed
the
fix-gitignore-escaped-trailing-spaces
branch
from
August 14, 2026 15:43
e3fb04f to
41762a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.gitignorelines likefoo\(escaped space followed by more spaces) were over-trimmed: only a single trailing\was preserved, so the pattern collapsed tofoo\and failed withdangling '\'.Git keeps the escaped trailing space. Match that by trimming only unescaped trailing spaces.
Fix
line.trim_right()with logic that only trims unescaped trailing spacesFixes #3485